﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary
{
    public class EvaluationService
    {
        public EvaluationService() { }

        public void AddEvaluation(Evaluation evaluation)
        {
            using (var ctx = new SystemContext())
            {
                if (evaluation == null) { return; }
                ctx.Evaluations.Add(evaluation);
                ctx.SaveChanges();
            }
        }
        public void DeleteEvaluation(Evaluation evaluation)
        {
            using (var ctx = new SystemContext())
            {
                var evaluation1 = ctx.Evaluations
                    .SingleOrDefault(s => s.EvaluationID == evaluation.EvaluationID);

                if (evaluation1 == null) { return; }
                ctx.Evaluations.Remove(evaluation1);
                ctx.SaveChanges();
            }
        }
        public void ModifyEvaluation(Evaluation evaluation)
        {
            DeleteEvaluation(evaluation);
            AddEvaluation(evaluation);
        }
        public List<Evaluation> GetAllEvaluation()
        {
            using (var ctx = new SystemContext())
            {
                return ctx.Evaluations
                    .ToList();
            }
        }
        public List<Evaluation> GetEvaluationByOrderID(string orderid)
        {
            using (var ctx = new SystemContext())
            {
                return ctx.Evaluations
                    .Where(s => s.EvaluationID == orderid)
                    .ToList();
            }
        }
        public List<Evaluation> GetEvaluationByUserID(string userid)
        {
            using (var ctx = new SystemContext())
            {
                return ctx.Evaluations
                    .Where(s => s.UserID == userid)
                    .ToList();
            }
        }
    }
}
